package com.bauer.java.spring.bean;

import javax.annotation.PostConstruct;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Author ：rui.wei
 * @Date ：Created in 14:58 2019/4/18
 * @Description：
 */
@Component
public class User implements InitializingBean, ApplicationContextAware {

    @NotBlank(message = "{com.bauer.java.spring.bean.User.userName.notBlank}")
    private String userName;

    @Value("${config.age}")
    private Integer age;

    @Autowired
    private ComponentTest componentTest;

    public User() {
        System.out.println("constructor User");
    }

    @PostConstruct
    public void init(){
        System.out.println("user PostConstruct");
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("user afterPropertiesSet");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("user setApplicationContext");
    }
}
